<?php

namespace common\models\business;

use Yii;

/**
 * This is the model class for table "new_business_inspection".
 *
 * @property string $id
 * @property string $business_person
 * @property integer $pigid
 * @property integer $createtime
 * @property integer $business_personid
 * @property string $lat
 * @property string $lng
 * @property string $address
 * @property integer $status
 * @property string $remark
 * @property integer $is_del
 */
class NewBusinessInspection extends \yii\db\ActiveRecord
{

    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '巡检',      //用于修改了什么的显示
        'mainfield' => 'id',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];



    const STATUS_PASSED = 1;
    const STATUS_UNPASSED = -1;
    const STATUS_NOLOOK = 0;

    //删除进入回收站
    const ISDEL_DEL = -1;
    const ISDEL_NODEL = 0;

    public static $statues = [
        self::STATUS_PASSED => '审核通过',
        self::STATUS_UNPASSED => '审核未通过',
        self::STATUS_NOLOOK => '未审核'
    ];



    const TYPE_BUJIAN = 1;
    const TYPE_DEFAULT = 0;
    public static $types = [
        self::TYPE_DEFAULT => '正常巡检',
        self::TYPE_BUJIAN => '补检',
    ];


    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'new_business_inspection';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['business_person', 'pigid', 'createtime', 'business_personid', 'status'], 'required'],
            [['pigid', 'createtime', 'business_personid', 'status', 'is_del'], 'integer'],
            [['lat', 'lng'], 'number'],
            [['business_person'], 'string', 'max' => 11],
            [['address'], 'string', 'max' => 255],
            [['remark'], 'string', 'max' => 500],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'business_person' => '巡检人员',
            'pigid' => '猪仔id',
            'createtime' => '巡检日期',
            'business_personid' => '巡检人员id',
            'lat' => '纬度',
            'lng' => '经度',
            'address' => '巡检提交数据的地址',
            'status' => '状态',
            'remark' => '审核备注',
            'is_del' => '是否删除',
            'type' => '巡检类型',
        ];
    }


    /**
     * @return \yii\db\ActiveQuery
     * 获取巡检的数据
     */
    public function getData()
    {
        return $this->hasMany(NewBusinessInspectionData::className(),['inspectionid'=>'id']);
    }





    /**
     * @return \yii\db\ActiveQuery
     * 获取巡检仔猪
     */
    public function getPig()
    {
        return $this->hasOne(BusinessPig::className(),['id'=>'pigid']);
    }

    /**
     * @return \yii\db\ActiveQuery
     * 巡检业务人员信息
     */
    public function getPerson()
    {
        return $this->hasOne(BusinessPerson::className(),['id'=>'business_personid']);
    }

    public function getBujian()
    {
        return $this->hasOne(NewBusinessInspection::className(),['bujian_id'=>'id']);
    }



}
